package com.dd.cloud.user.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.dd.cloud.user.entity.admin.Feedback;
import com.dd.cloud.user.entity.admin.FeedbackReply;
import com.dd.cloud.user.entity.admin.ProblemHelp;
import com.dd.cloud.user.entity.admin.ProblemHelpType;
import com.dd.cloud.user.req.admin.*;
import com.dd.cloud.user.res.admin.FeedbackDocPageRes;
import com.dd.cloud.user.res.admin.FeedbackPageRes;
import com.dd.cloud.user.service.admin.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * <p>
 * 反馈的回复表 前端控制器
 * </p>
 *
 * @author czg
 * @since 2022-05-07
 */
@RestController
@RequestMapping("/feedback")
@Validated
public class FeedbackController {
    @Autowired
    private IFeedbackService feedbackService;
    @Autowired
    private IFeedbackReplyService feedbackReplyService;
    @Autowired
    private IProblemHelpService problemHelpService;
    @Autowired
    private IProblemHelpTypeService problemHelpTypeService;
    @Autowired
    private IProblemHelpClickService problemHelpClickService;

    /**
     * 添加反馈
     *
     * @return
     */
    @PostMapping("/add")
    public ResponseEntity<Void> addFeedback(@Valid Feedback feedback) {
        feedbackService.addFeedback(feedback);
        return ResponseEntity.ok().build();
    }

    /**
     * 分页查询反馈记录 医生查询自己的反馈内容
     *
     * @return
     */
    @GetMapping("/page")
    public ResponseEntity<IPage<FeedbackDocPageRes>> getFeedbackPage(@Valid FeedbackPageReq req) {
        IPage<FeedbackDocPageRes> page = feedbackService.getFeedbackPage(req);
        return ResponseEntity.ok(page);
    }

    /**
     * 分页查询反馈记录 管理员查询全部
     *
     * @return
     */
    @GetMapping("/page/admin")
    public ResponseEntity<IPage<FeedbackPageRes>> getFeedbackPageAdmin(@Valid FeedbackPageReq req) {
        IPage<FeedbackPageRes> page = feedbackService.getFeedbackPageByAdmin(req);
        return ResponseEntity.ok(page);
    }

    /**
     * 修改反馈状态
     *
     * @return
     */
    @PostMapping("/update/status")
    public ResponseEntity<Void> updateFeedbackStatus(@NotNull(message = "反馈id不能为空") Integer id, @NotNull(message = "反馈状态不能为空") Integer status) {
        feedbackService.updateFeedbackStatus(id, status);
        return ResponseEntity.ok().build();
    }

    /**
     * 添加反馈的回复
     *
     * @return
     */
    @PostMapping("/reply/add")
    public ResponseEntity<Void> addReply(@Valid FeedbackReply reply) {
        feedbackReplyService.addReply(reply);
        return ResponseEntity.ok().build();
    }

    /**
     * 修改反馈的回复状态
     *
     * @return
     */
    @PostMapping("/reply/update/status")
    public ResponseEntity<Void> replyUpdateStatus(@NotNull(message = "回复的id不能为空") String ids, @NotNull(message = "状态不能为空") Integer status) {
        feedbackReplyService.updateReplyStatus(ids, status);
        return ResponseEntity.ok().build();
    }

    /**
     * 查询反馈的回复
     *
     * @return
     */
    @GetMapping("/reply/list")
    public ResponseEntity<List<FeedbackReply>> replyList(@NotNull(message = "反馈的id不能为空") Integer id) {
        List<FeedbackReply> list = feedbackReplyService.getReplyPage(id);
        return ResponseEntity.ok(list);
    }

    /**
     * 查询问题类型列表
     *
     * @param status
     * @return
     */
    @GetMapping("/problem/type/list")
    public ResponseEntity<List<ProblemHelpType>> getProblemTypeList(@RequestParam(required = false) Integer status) {
        List<ProblemHelpType> list = problemHelpTypeService.getProblemTypeList(status);
        return ResponseEntity.ok(list);
    }

    /**
     * 添加问题帮助类型
     *
     * @return
     */
    @PostMapping("/problem/type/add")
    public ResponseEntity<Void> addProblemHelpType(@RequestBody @Valid AddProblemHelpTypeReq req) {
        problemHelpTypeService.addProblemHelpType(req);
        return ResponseEntity.ok().build();
    }

    /**
     * 修改问题帮助类型
     *
     * @return
     */
    @PostMapping("/problem/type/update")
    public ResponseEntity<Void> updateProblemHelpType(@RequestBody @Valid UpdateProblemHelpTypeReq req) {
        problemHelpTypeService.updateProblemHelpType(req);
        return ResponseEntity.ok().build();
    }

    /**
     * 修改问题帮助类型
     *
     * @return
     */
    @PostMapping("/problem/type/update/status")
    public ResponseEntity<Void> updateProblemHelpTypeStatus(@NotNull(message = "帮助id不能为空") Integer id, @NotNull(message = "帮助的状态不能为空") Integer status) {
        problemHelpTypeService.updateProblemHelpTypeStatus(id, status);
        return ResponseEntity.ok().build();
    }

    /**
     * 分页查询帮助内容
     *
     * @return
     */
    @GetMapping("/problem/page")
    public ResponseEntity<IPage<ProblemHelp>> getProblemPage(@Valid GetProblemHelpPageReq req) {
        IPage<ProblemHelp> page = problemHelpService.getProblemPage(req);
        return ResponseEntity.ok(page);
    }

    /**
     * 查询问题帮助
     *
     * @return
     */
    @GetMapping("/problem/list")
    public ResponseEntity<List<ProblemHelp>> getProblemList() {
        List<ProblemHelp> res = problemHelpService.getProblemList();
        return ResponseEntity.ok(res);
    }

    /**
     * 查询帮助内容 通过id
     *
     * @return
     */
    @GetMapping("/problem/one")
    public ResponseEntity<ProblemHelp> getProblem(@NotNull(message = "id不能为空") Integer id) {
        ProblemHelp help = problemHelpService.getProblem(id);
        return ResponseEntity.ok(help);
    }

    /**
     * 添加问题帮助
     *
     * @return
     */
    @PostMapping("/problem/add")
    public ResponseEntity<Void> addProblemHelp(@RequestBody @Valid AddProblemHelpReq req) {
        problemHelpService.addProblemHelp(req);
        return ResponseEntity.ok().build();
    }

    /**
     * 修改问题帮助
     *
     * @return
     */
    @PostMapping("/problem/update")
    public ResponseEntity<Void> updateProblemHelp(@RequestBody @Valid UpdateProblemHelpReq req) {
        problemHelpService.updateProblemHelp(req);
        return ResponseEntity.ok().build();
    }

    /**
     * 修改问题帮助状态
     *
     * @return
     */
    @PostMapping("/problem/update/status")
    public ResponseEntity<Void> updateStatusProblemHelp(@NotNull(message = "帮助id不能为空") Integer id, @NotNull(message = "帮助的状态不能为空") Integer status) {
        problemHelpService.updateStatusProblemHelp(id, status);
        return ResponseEntity.ok().build();
    }

    /**
     * 问题点击[有用/没用]按钮
     *
     * @param problemId 问题id
     * @param type      点击类型 1有用 2没用
     */
    @PostMapping("/problem/click")
    public ResponseEntity<Void> problemHelpClick(@NotNull(message = "问题id不能为空") Integer problemId, @NotNull(message = "点击类型不能为空") Integer type) {
        problemHelpClickService.problemHelpClick(problemId, type);
        return ResponseEntity.ok().build();
    }
}

